package bud.web.boardqa.service;

import java.util.List;

import bud.vo.BoardFormDTO;
import bud.vo.BoardQADTO;
import bud.web.boardqa.dao.IBoardqaDao;

public class BoardqaServiceImpl implements IBoardqaService {

	IBoardqaDao dao;
	
	public IBoardqaDao getDao() {
		return dao;
	}

	public void setDao(IBoardqaDao dao) {
		this.dao = dao;
	}

	@Override
	public List<BoardQADTO> getBoardqaList(BoardFormDTO formDTO) {
		return dao.getBoardqaList(formDTO);
	}

	@Override
	public int getBoardqaCount(BoardFormDTO formDTO) {
		return dao.getBoardqaCount(formDTO);
	}

	@Override
	public BoardQADTO getBoardqa(Integer qa_no) {
		return dao.getBoardqa(qa_no);
	}

	@Override
	public BoardqaResult createBoardqa(BoardQADTO boardqa) {
		int pk = dao.insertBoardqa(boardqa);
		if(pk>0) {
			return BoardqaResult.OK;
		}else {
			return BoardqaResult.FAILED;
		}
	}

	@Override
	public BoardqaResult modifyBoardqa(BoardQADTO boardqa) {
		BoardQADTO tempBoard = dao.getBoardqa(boardqa.getQa_no());
		if(tempBoard==null) {
			return BoardqaResult.FAILED;
		}else {
			if(tempBoard.getQa_pass().equals(boardqa.getQa_pass())) {
				int result =dao.updateBoardqa(boardqa);
				if(result>0) {
					return BoardqaResult.OK;
				}else {
					return BoardqaResult.FAILED;
				}
			} else {
				return BoardqaResult.INVALIDPASSWORD;
			}
		} 
	}

	@Override
	public BoardqaResult removeBoardqa(BoardQADTO boardqa) {
		BoardQADTO tempBoard = dao.getBoardqa(boardqa.getQa_no());
		if(tempBoard==null) {
			return BoardqaResult.FAILED;
		}else {
			if(tempBoard.getQa_pass().equals(boardqa.getQa_pass())) {
				int result =dao.deleteBoardqa(boardqa.getQa_no());
				if(result>0) {
					return BoardqaResult.OK;
				}else {
					return BoardqaResult.FAILED;
				}
			} else {
				return BoardqaResult.INVALIDPASSWORD;
			}
		} 
	}

	@Override
	public int getBoardqaDepthCount(BoardQADTO boardqa) {
		return dao.getBoardqaDepthCount(boardqa);
	}

}
